var tgd = tgd || {};
tgd.Contests = tgd.Contests || {};
tgd.Contests.SameGame = tgd.Contests.SameGame || {};
tgd.Contests.SameGame.Solver = tgd.Contests.SameGame.Solver || {};
tgd.Contests.SameGame.View = tgd.Contests.SameGame.View || {};



tgd.Contests.SameGame.Puzzle = function (conf) {
	var _id = parseInt(conf.match(/^\d+/));
	var _numColumns = parseInt(conf.match(/\d+(?=:)/g)[1]);
	var _cells = conf.match(/\d+(?=,|$)/g);
	var _rows = new Array();
	var color;
	var _colorList = new Array();

	for (var i = 0; i < _cells.length; ++i) {
		if (i % _numColumns == 0) {
			_rows.push(new Array());
		}
		color = parseInt(_cells[i])
		_colorList[color] = true;
		_rows[_rows.length - 1].push(color);
	}

	this.__defineGetter__("ID", function() { return _id; });
	this.__defineGetter__("NumColumns", function() { return _numColumns; });
	this.__defineGetter__("NumRows", function() { return _rows.length; });
	this.__defineGetter__("NumColors", function() { return _colorList.length - 1; });
	this.__defineGetter__("Grid", function() { return _rows; });

	this.toString = function() {
		return "ID: " + this.ID + "   # Rows: " + this.NumRows + "   # Columns: " + this.NumColumns;
	}
}
